package CtrLayer;

import ModelLayer.SalesOrder;
import DBLayer.*;

import java.util.ArrayList;
import java.util.Date;






public class CtrSalesOrder {

		public CtrSalesOrder(){
			
			
		}
		public ArrayList<SalesOrder> getAllSalesOrdersByCustomerId(int customerId){
			IFDbSalesOrder dbSalesOrder = new DbSalesOrder();
			return dbSalesOrder.getAllSalesOrdersByCustomerId(customerId, true);
		}
		
		public ArrayList<SalesOrder> getAllSalesOrders(){
			IFDbSalesOrder dbSalesOrder=new DbSalesOrder();
			ArrayList<SalesOrder> allSalesOrder=new ArrayList<SalesOrder>();
			allSalesOrder=dbSalesOrder.getAllSalesOrders(false);
			return allSalesOrder;
		}
		public SalesOrder getSaleOrderById(int salesOrderId){
			IFDbSalesOrder dbsalesOrder=new DbSalesOrder();
			return dbsalesOrder.getSaleOrderById(salesOrderId, true);
		}
		public int updateSalesOrder(int salesOrderId, Date date, int amount, Date deliveryDate, Boolean deliveryStatus){
			IFDbSalesOrder dbsalesOrder=new DbSalesOrder();
			SalesOrder salesOrder=new SalesOrder(salesOrderId, date, amount, deliveryDate, deliveryStatus);
			return dbsalesOrder.updateSalesOrder(salesOrder);
		}
		
		public void insertSalesOrder(int salesOrderId, Date date, int amount, Date deliveryDate, Boolean deliveryStatus){
			SalesOrder salesOrderObj=new SalesOrder(salesOrderId, date, amount, deliveryDate, deliveryStatus);
			
			try{
				DbConnection.startTransaction();
				DbSalesOrder dbsalesOrder=new DbSalesOrder();
				dbsalesOrder.insertSalesOrder(salesOrderObj);
				DbConnection.commitTransaction();
			}
			catch(Exception e)
			{
				DbConnection.rollbackTransaction();
			}
		}
		
		public void deleteOrder(int orderId) {
			IFDbSalesOrder dbsalesOrder=new DbSalesOrder();
			dbsalesOrder.deleteOrder(orderId);
		}
}
